/**
 * 
 */
package com.itboye.allshengmedical.sci.cmd.req;

import com.itboye.allshengmedical.sci.packet.req.BaseReqPacket;

import android.R.integer;
import android.util.Log;

/**
 * @author 贝贝 346551990@qq.com
 * @date 2016-12-8
 */
public class BaseCmd implements IReqCommand {
	int TIMEOUT = 1500;
	int UPDATETIMEOUT = 20000;
	long sendTimeStamp = 0;
	CmdType cmdType;
	BaseReqPacket baseReqPacket;

	public boolean isTimeOut() {
		return sendTimeStamp >= 0
				&& System.currentTimeMillis() - sendTimeStamp >= TIMEOUT;
	}

	public boolean isTimeOut(long currentTimeMillis, CmdType cmdType) {
		if (cmdType.equals(CmdType.UpdateArm)
				|| cmdType.equals(CmdType.Unknown)
				|| CmdType.SelfCheck.equals(cmdType)) {
			return sendTimeStamp >= 0
					&& currentTimeMillis - sendTimeStamp >= UPDATETIMEOUT;
		} else if (cmdType.equals(CmdType.DetectLightIntensitTemp)) {
			return sendTimeStamp >= 0
					&& currentTimeMillis - sendTimeStamp >= 3000;
		} else {
			return sendTimeStamp >= 0
					&& currentTimeMillis - sendTimeStamp >= TIMEOUT;
		}

	}

	public BaseCmd() {
		// TODO Auto-generated constructor stub
	}

	public BaseReqPacket getBaseReqPacket() {
		return baseReqPacket;
	}

	public void setBaseReqPacket(BaseReqPacket baseReqPacket) {
		this.baseReqPacket = baseReqPacket;
		setCmdType(baseReqPacket.getCmdType());
	}

	// long receiveTimeStamp = 0;

	public CmdType getCmdType() {
		return cmdType;
	}

	public void setCmdType(CmdType cmdType) {
		this.cmdType = cmdType;
	}

	public int getTIMEOUT() {
		return TIMEOUT;
	}

	public long getSendTimeStamp() {
		return sendTimeStamp;
	}

	public void setSendTimeStamp(long sendTimeStamp) {
		this.sendTimeStamp = sendTimeStamp;
	}

	public void setTIMEOUT(int tIMEOUT) {
		TIMEOUT = tIMEOUT;
	}

	@Override
	public byte[] convertBytes() {
		// TODO Auto-generated method stub
		return getBaseReqPacket().toBytes();
	}

}
